package com.chat.biz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chat.api.dto.AuthAddFriendRequestDTO;
import com.chat.api.dto.AuthAgreeFriendRequestDTO;
import com.chat.api.dto.AuthFriendRequestPageDTO;
import com.chat.api.entity.FriendRequest;
import com.chat.api.vo.AuthFriendRequsetPageVO;
import com.chat.biz.service.FriendRequestService;
import com.chat.common.page.PageParam;
import com.chat.common.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友请求控制器
 *
 * @author chenhao
 * @date 2025/06/09
 *//*
*功能：
 作者：chenhao
*日期： 2025/6/7 下午7:53
*/
@RestController
@RequestMapping("/friendrequest")
public class FriendRequestController {
    @Autowired
    private FriendRequestService friendRequestService;

    /**
     * 好友请求页面
     *
     * @param page 页
     * @param dto 到
     * @return {@link R }<{@link Page }<{@link AuthFriendRequsetPageVO }>>
     */
    @GetMapping("page")
    public R<Page<AuthFriendRequsetPageVO>> FriendRequestPage(@PageParam Page page, AuthFriendRequestPageDTO dto){
        return R.ok(friendRequestService.FriendRequestPage(page,dto));
    }

    /**
     * 添加请求
     *
     * @param dto 到
     * @return {@link R }<{@link Void }>
     */
    @PostMapping("addrequest")
    public R<Void> addRequest(@RequestBody AuthAddFriendRequestDTO dto){
        friendRequestService.addRequest(dto);
        return R.ok();
    }

    /**
     * 处理
     *
     * @param dto 到
     * @return {@link R }<{@link Void }>
     */
    @PostMapping("handle")
    public R<Void> handle(@RequestBody AuthAgreeFriendRequestDTO dto){
        friendRequestService.handlerequest(dto);
        return R.ok();
    }

    /**
     * 列表
     *
     * @param toUserId 到用户id
     * @return {@link R }<{@link List }<{@link FriendRequest }>>
     */
    @GetMapping("list")
    public R<List<FriendRequest>> list(@RequestParam("toUserId") String toUserId){
        return R.ok(friendRequestService.selectList(toUserId));
    }

}
